package com.lz.football.module.compete
{
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.liangzhong.constants.ClubConst;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.CompeteEvent;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.compete.CompeteDataManager;
	import com.lz.football.module.compete.item.InlandResultItem;
	import com.lz.football.module.compete.item.RankItem;
	
	import common.BaseView.BaseView;
	
	import flash.display.Shape;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class MapView extends BaseView
	{
		private var _rankItemVec:Vector.<RankItem>;
		public function MapView()
		{
			super();
		}
		override public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.lz.modul.compete.mapView");
			this.addChild(symbolSkin);
			symbolSkin.cacheAsBitmap = true;
			symbolSkin.mapMc.gotoAndStop(5);
			initItem();
			addEvtListener();
		}
		override public function addEvtListener():void
		{
//			this.addEventListener(MouseEvent.CLICK,onClickHandler);
			
		}
		//获取坐标点
		protected function onClickHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			trace("["+event.currentTarget.mouseX+","+event.currentTarget.mouseY+"],");
//			
			var shape:Shape = new Shape();
			shape.graphics.clear();
			shape.graphics.beginFill(0xFF00FF);
			shape.graphics.drawCircle(event.currentTarget.mouseX,event.currentTarget.mouseY,5);
			shape.graphics.endFill();
			this.addChild(shape);
			
			
//			var item:InlandResultItem = new InlandResultItem();
//			item.getData(null);
//			GlobalDef.GameContainer.addChild(item);
//			item.x = GlobalDef.StageWidth>> 1;
//			item.y = GlobalDef.StageHeight>> 1;
//			item.y = 400;
			
			
//			AppEventDispatcher.getInstance().dispatchEvent(new Event("test"));
		}
		
		/**
		 *初始化item 
		 * 
		 */
		private function initItem():void
		{
			_rankItemVec = new Vector.<RankItem>();
			var item:RankItem;
			for(var i:int = 0;i < 10;i++)
			{
				item = new RankItem();
				_rankItemVec.push(item);
				item.callBack = selectItem;
				
			}
		}
		private var _changellView:SingleChaglleView;
		/**
		 *选择了；item; 
		 * @param $id
		 * 
		 */
		private function selectItem($id:int):void
		{
//			alert
			
//			if( _changellView == null)
//			{
//				_changellView = new SingleChaglleView();
//				_changellView.initUI();
//			}
//			GlobalDef.GameContainer.addChild(_changellView);
			
//			
		}
		/**
		 *更新列表 
		 * 
		 */
		public function updataList():void
		{
			symbolSkin.mapMc.gotoAndStop(AppData.getInstance().competeDataManager.competeInfoVo.rivalcountry);
			var arr:Array = AppData.getInstance().competeDataManager.opponentRankList;
			var len:int = arr.length > _rankItemVec.length?10:arr.length;
			var pointList:Array;
			switch(AppData.getInstance().competeDataManager.competeInfoVo.rivalcountry)
			{
				case ClubConst.COUNTRY_ENGLAND:
					pointList = CompeteDataManager.ENGLANDPOINT;
					break;
				case ClubConst.COUNTRY_SPAIN:
					pointList = CompeteDataManager.SPAINPOINT;
					break;
				case ClubConst.COUNTRY_FRANCE:
					pointList = CompeteDataManager.FRANCEPOINT;
					break;
				case ClubConst.COUNTRY_GERMANY:
					pointList = CompeteDataManager.GERMANYPOINT;
					break;
				case ClubConst.COUNTRY_ITALY:
					pointList = CompeteDataManager.ITALYpoint;
					break;
				case ClubConst.COUNTRY_CHAIN:
					pointList = CompeteDataManager.CHINEPOINT;
					break;
			}
			for(var i:int = 0;i< len;i++)
			{
				_rankItemVec[i].setData(arr[i]);
				var point:Array = pointList[i];
				_rankItemVec[i].x = point[0];
				_rankItemVec[i].y = point[1];
				this.addChild(_rankItemVec[i]);
			}
			
		}
		/**
		 * 
		 * 
		 */
		override public function destroyView():void
		{
			while(_rankItemVec.length)
			{
				_rankItemVec.pop().destroyView();
			}
			_rankItemVec = null;
			super.destroyView();
		}
	}
}